Skip to main content

How to modify the camera projection by script using Java

How to Modify the Camera projection by script using Java


In your Java class, do the following:

public class YourClass extends Component {

// values ​​to control the field of view and diameter of the camera projection
public float fieldOfView = 35f, diameter = 5f; // select in properties

// creates a new SUIButton
public SUIButton button; // select in properties

// creates a new Camera
public Camera camera; // select in properties

// boolean to control Camera projection
private boolean stateController;

@Override
public void start() {

}

@Override
public void repeat() {

// checking if the button was pressed
if (button.isDown()) {

// changing the boolean value to true and false with each button press if the conditional is true
stateController = !stateController;
}

// checking if the boolean is true
if (stateController) {

// changing Camera projection to 3D
camera.setProjection(0);

// changing the field of view of the Camera's 3D projection
camera.setFov(fieldOfView);

// returning if the conditional is true, everything below this line will only be executed if the conditional is false
return;
}

// changing Camera projection to 2D
camera.setProjection(1);

// changing the diameter of the Camera's 2D projection
camera.setOrthoDiameter(diameter);
}
}